/**
 * @param {number} num
 * @returns
 */
function num16 (num) {
    const res = num.toString(16);
    return res.length === 1 ? 0 + res : res;
}

function rgba2color(input) {
    const [r, g, b, a] = input.match(/[0-9]+([.]{1}[0-9]+){0,1}/g).map(item => Number(item));
    return `color: #${num16(r)}${num16(g)}${num16(b)}; opacity: ${a};`;
}

console.log(rgba2color('rgba(255, 0, 0, 0.5)')); // 'color: #ff0000; opacity: 0.5;'
console.log(rgba2color('rgba(254, 0, 103, 0.9)')); // 'color: #fe0067; opacity: 0.9;'
